package org.yray.io.sentinel;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;

import java.util.concurrent.atomic.AtomicInteger;

public class SentinelThread extends Thread {
    private AtomicInteger i ;
    private AtomicInteger j ;
    public SentinelThread(AtomicInteger i,AtomicInteger j)
    {
        this.i=i;
        this.j=j;
    }
    @Override
    public void run() {

        Entry entry = null;
        try {
            entry = SphU.entry("HelloWorld");
            /*您的业务逻辑 - 开始*/
            Thread.sleep(1000);
            System.out.println("finish:"+i.incrementAndGet()+"="+System.currentTimeMillis());
            /*您的业务逻辑 - 结束*/
        } catch (BlockException e1) {
            /*流控逻辑处理 - 开始*/
            System.out.println("block" + j.incrementAndGet() +"="+System.currentTimeMillis());

            /*流控逻辑处理 - 结束*/
        } catch (Exception e) {

        }
        finally {
            if (entry != null) {
                entry.exit();
            }

        }
    }
}
